﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Eis51.CampanyCMS.Model.Bus;
using Eis51.CampanyCMS.Business;

using Eis51.CampanyCMS.FrameWork;
using System.Data;





using Eis51.CampanyCMS.Model;
using Eis51.CampanyCMS.Model.BaseInfoMng;
using Eis51.CampanyCMS.Business.OnlineService;
using Eis51.CampanyCMS.Business.BaseInfoMng;
using Eis51.Web.Admin;
namespace Eis51.CampanyCMS.WebUI.Admin.Baseinfo
{
    public partial class accessStatistics : BasePage
    {
         

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowData();
            }
        }

        private void ShowData()
        {
            string sql = "select * from CompanyInfo where CreateBy='{0}'  and Licd={1} ";
            sql = string.Format(sql, AppContext.CurrentAdministrator.UserName, AppContext.LCID  );
            Companyinfo c = null;
            DataTable dt = BaseChatToolsBLL.GetInstance().GetDataTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                c = Companyinfo.Dr2Obj(dt.Rows[0], Companyinfo.ColumnNameEnum.DBName);
                if (c != null)
                {
                    UControl.CopyEntityToControl(this.Page.Form, c); 
                }
            }
        }
      



        private bool Save()
        {
            Companyinfo c = new Companyinfo();
            
            string sql = "select * from CompanyInfo where CreateBy='{0}' and Licd={1}  ";
            sql = string.Format(sql, AppContext.CurrentAdministrator.UserName,AppContext.LCID );
            DataTable dt = BaseChatToolsBLL.GetInstance().GetDataTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                c = Companyinfo.Dr2Obj(dt.Rows[0], Companyinfo.ColumnNameEnum.DBName);
            }
            UControl.CopyControlToEntity(this.Page.Form, c);
             

            if (dt != null && dt.Rows.Count > 0)
            {
                CompanyinfoBLL.GetInstance().Update(c);
            }
            else
            {
               
                c.Licd = AppContext.LCID ;
                c.Createby = AppContext.CurrentAdministrator.UserName;
                c.Createdate = DateTime.Now;
                CompanyinfoBLL.GetInstance().Insert(c);
            }
            return true;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Save();
            ShowData();
            BaseTools.ShowMessage(this.Page, "提交成功！");
        }
        
    }
}
